import _regeneratorRuntime from "@babel/runtime/regenerator";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - CA证书管理
 * @date: 2019/9/10
 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询证书列表
 * @param {object} payload - 分页参数
 */

export function queryList() {
  return _queryList.apply(this, arguments);
}
/**
 * 删除证书
 * @param {object} payload - 选中的证书
 */

function _queryList() {
  _queryList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var payload,
        param,
        _args = arguments;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            payload = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
            param = parseParameters(payload);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/certificates") : "".concat(CPAAS_PLATFORM, "/v1/certificates"), {
              query: _objectSpread({}, param)
            }));

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryList.apply(this, arguments);
}

export function deleteCa(_x) {
  return _deleteCa.apply(this, arguments);
}

function _deleteCa() {
  _deleteCa = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(payload) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/certificates") : "".concat(CPAAS_PLATFORM, "/v1/certificates"), {
              method: 'DELETE',
              body: payload
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _deleteCa.apply(this, arguments);
}